<%@ page language="java"
import="java.util.*,com.wechat.service.WechatService,
com.base.bean.*,com.base.dao.*,com.base.service.*,tool.*"
pageEncoding="UTF-8"%>
<%
//注意生成注入对象的时候 一定要去掉端口号
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() +  path + "/"; %>
<%
WechatService ws = WechatService.getInstance(); 

ValueStack vs=(ValueStack)request.getAttribute("struts.valueStack");
String openId=(String)vs.findValue("openId");
String url = basePath + "daka"+"?openId="+openId;

String photoUrl=(String)vs.findValue("photoUrl");


%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %> 
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HIFO</title>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
<link rel="stylesheet" href="lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/main.css">   
<script src="lib/jquery-2.1.1.min.js"></script>
<script src="lib/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<%@ include file="_daohang.jsp" %>	

<!-- 每个页面的模板，以下是正文 -->    
<div class="container">



<div class="row">
<div class="col-xs-12 hide">
	<form id="form1" action="daka?openId=<s:property value="openId"/>" method="post">
	
	
	<input type="text" value="<s:property value="tip"/>">
	<input id="photoUrl" name="photoUrl" type="text" value="<s:property value="photoUrl"/>" >
	<input id="longitude" name="longitude"  type="text" >
	<input id="latitude" name="latitude" type="text">
	<input id="imgIds" name="imgIds" type="text" >
	<button class="form-control" id="checkJsApi">checkJsApi</button>
	</form><!-- 隐藏域 传递数据用  -->
</div></div> <!-- col-xs-12|row  -->

<div class="row"> 
<div class="panel panel-default">
<s:if test='state==0'>
<div class="panel-heading">	
<div class="row">
	<div class="col-xs-4"><button id="chooseImage" class="form-control btn btn-info" >拍照</button></div>
    <div class="col-xs-4"><button id="uploadImage" class="form-control btn btn-info" >上传</button></div>
     <div class="col-xs-4"><button id="getLocation" class="form-control btn btn-primary">打卡</button></div> 
     <!--  
     <div class="col-xs-4 hide"><button id="previewImage" type="button" class="btn btn-success">照片预览</button></div> -->
     <div class="col-xs-4 hide"><button id="previewImage" type="button" class="btn btn-info">照片查看</button></div>
</div>


</s:if>
<s:elseif test='state==1'>
<div class="panel-heading">
<div class="row">
	<div class="col-xs-4"></div>
    <div class="col-xs-4"><button type="button" class="btn btn-success">打卡成功</button></div>
     
     <!-- 
     <div class="col-xs-4"><a class="btn btn-default" href="<s:property value="photoUrl"/>" role="button">照片查看</a></div>
     <div class="col-xs-4"><a class="btn btn-default" href="<s:property value="photoUrl"/>" role="button">照片查看</a></div> 
     <div class="col-xs-4"><button id="previewImage" type="button" class="btn btn-info">照片查看</button></div>-->
</div>

	
</div>
</s:elseif>


</div>
<div  class="panel-body">

<table class="table table-condensed">
<tr class="success">
<td colspan="4" class="info"><s:property value="datetime"/>---显示最近5条记录</td>
</tr>
<s:iterator value="dks" id="dk" status="index">
<tr class="success">
<td class="active" width="50">
<s:if test='#dk.checked==0'>
待审
</s:if>
<s:elseif test='#dk.checked==1'>
通过
</s:elseif>
<s:elseif test='#dk.checked==2'>
无效
</s:elseif>
<s:elseif test='#dk.checked==3'>
重复
</s:elseif>
<s:elseif test='#dk.checked==4'>
其他
</s:elseif>
</td>

<td class="active" width="50"><s:property value="#dk.created.toString().substring(5,10)"/></td>
<td class="active" width="50"><s:property value="#dk.created.toString().substring(11,16)"/></td>
<td class="active"><s:property value="#dk.addName"/>附近</td>
<td class="active" width="30"><a class="btn btn-default" href="http://we.51waji.com/picture/<s:property value="#dk.path"/>/<s:property value="#dk.photoName"/>" role="button">查看</a></td>
</tr>

<tr><td colspan=5>审核备注：<s:property value="#dk.checkmemo"/></td></tr>

</s:iterator>  
</table>

</div><!-- panel-body -->


<!-- <button class="btn btn_primary" id="check">检查</button> -->
</div><!-- panel-default -->
</div><!-- row  -->
</div><!-- container  -->

</body>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script><%=ws.wxConfig(url) %></script>

<script>


var images = {
		    localId: [],
		    serverId: []
		  };


wx.ready(function () {
// 1 判断当前版本是否支持指定 JS 接口，支持批量判断
document.querySelector('#checkJsApi').onclick = function () {
  wx.checkJsApi({
    jsApiList: [
      'getNetworkType',
      'previewImage'
    ],
    success: function (res) {
      alert(JSON.stringify(res));
    }
  });
};

var images = {
		    localId: [],
		    serverId: []
		  };

document.querySelector('#chooseImage').onclick = function () {
  wx.chooseImage({
	count: 1, // 默认9
	sizeType: ['compressed'], 
	sourceType: ['camera'],
    success: function (res) {
      images.localId = res.localIds;
      alert('已选择 ' + res.localIds.length + ' 张照片');
    }
  });
};


document.querySelector('#uploadImage').onclick = function () {
	    if (images.localId.length == 0) {
	      alert('还没有选择图片');
	      return;
	    }
	    var i = 0, length = images.localId.length;
	   
	    images.serverId = [];
	    function upload() {
	      wx.uploadImage({
	        localId: images.localId[i],
	        success: function (res) {
	          i++;
	          alert('已上传：' + i + '/' + length);
	          images.serverId.push(res.serverId);
	          $('#imgIds').val(images.serverId.join());
	          if (i < length) {
	            upload();
	          }
	        },
	        fail: function (res) {
	          alert(JSON.stringify(res));
	        }
	      });
	    }
	    upload();
	    
	  };

 // 5.2 图片预览
document.querySelector('#previewImage').onclick = function () {
    wx.previewImage({
      current: '<%=photoUrl%>',
      urls: [
        '<%=photoUrl%>'
      ]
    });
  };



document.querySelector('#getLocation').onclick = function () {
  $(this).attr("disabled","disabled");
  
  wx.getLocation({
    type: 'gcj02', // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
    success: function (res) {
 
      //alert(JSON.stringify(res));
      $('#longitude').val(res.longitude);
      $('#latitude').val(res.latitude);
      $("#getLocation").removeAttr("disabled");
      
      $("#form1").submit();
      alert("提交成功");
    },
    cancel: function (res) {
      alert('用户拒绝授权获取地理位置');
    }
  });
};


});

wx.error(function (res) {
alert(res.errMsg);
});

</script>
</html>


















